<template>
  <el-switch v-model="scope.row.inHome"
             active-color="#13ce66"
             inactive-color="#DCDFE6"
             :active-value="1"
             :inactive-value="0"
             @change="handleSwitch(scope.row)">
  </el-switch>
</template>

<script>
import { dtEquipment } from "@/api/index";

export default {
  name: 'SwitchCloumn',
  props: {
    scope: {
      type: Object,
      default: () => { }
    }
  },
  methods: {
    // 表格是否在公司
    handleSwitch (row) {
      const params = { deviceCode: row.iMEICode, inHome: row.inHome };
      this.$confirm(
        `${row.inHome == 1 ? `是否在公司？` : `是否不在公司？`}`,
        "提示"
      )
        .then(async (res) => {
          let response = await dtEquipment.getDtSetInHome(params);
          if (response?.data?.code === 0) {
            this.$nextTick(() => {
              this.$message.success(response?.data?.message);
              this.$emit('handleSwitch')
            });
          } else {
            this.$message.error(response?.data?.message);
          }
        })
        .catch((err) => {
          row.inHome = row.inHome === 1 ? 0 : 1;
          console.log(err);
        });
    },
  }
}
</script>

<style>
</style>